define(['moment'], function (moment) {
    return ['$rootScope', '$scope', '$filter', '$stateParams', 'config', 'MMWService', '$compile', '$timeout', '$window',
        function ($rootScope, $scope, $filter, $stateParams, config, $MMWService, $compile, $timeout, $window) {
            $scope.init = function(){
                $scope.$root.currentState = $stateParams.data.report_id;
                $scope.title = $stateParams.data.report_name;
                if($stateParams.data.report_url == undefined)
                    userCustomReportFormatGet($stateParams.data.report_id, function(data){
                        showReport($stateParams.data.outside_url + '?formlet='+data.reporturl_link);
                    });
                else
                    showReport($stateParams.data.report_url);
            };

            $scope.back = function(){
                $scope.$root.hideMenu();
                $scope.$root.changeProgram('home', true);
            };

            function showReport(url){
                $scope.$root.showLoading();
                var report_content = document.getElementById('report-content');
                report_content.addEventListener('load', function(arg){
                    $scope.$root.hideLoading();
                });
                report_content.src= url;
            }

            function userCustomReportFormatGet(report_id, callback){
                $MMWService.sendToServer({
                    uri : 'ServicesSTD.Module_SYS.user_custom_report_format_get',
                    content : {report_id:report_id},
                    success : function(data){
                        callback(data);
                    }
                });
            }
        }
];});
